package com.nbot.server.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nbot.server.domain.ChecklogDO;
import com.nbot.server.service.ChecklogService;
import com.nbot.server.util.PageUtils;
import com.nbot.server.util.Query;
import com.nbot.server.util.R;
import com.nbot.server.annotation.Log;

/**
 * 
 *
 * @author nbot
 * @email nbot@163.com
 * @date 2018-06-22 00:42:57
 */

@Controller
@RequestMapping("/server/checklog")
public class ChecklogController {
    @Autowired
    private ChecklogService checklogService;

    @GetMapping()
    @RequiresPermissions("server:checklog:checklog")
    String Checklog() {
        return "server/checklog/checklog" ;
    }

    @ResponseBody
    @Log("查看")
    @GetMapping("/list")
    @RequiresPermissions("server:checklog:checklog")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        Map<String,Object> mapTemp = new HashMap<String,Object>();
        ViewChklogCountController.CovertMapTime(query, mapTemp);
        List<ChecklogDO> chklogPointDiAnaList = checklogService.list(mapTemp);
        int total = checklogService.count(mapTemp);
        PageUtils pageUtils = new PageUtils(chklogPointDiAnaList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("server:checklog:add")
    String add() {
        return "server/checklog/add" ;
    }

    @GetMapping("/edit/{autoid}")
    @RequiresPermissions("server:checklog:edit")
    String edit(@PathVariable("autoid") Long autoid, Model model) {
            ChecklogDO checklog = checklogService.get(autoid);
        model.addAttribute("checklog" , checklog);
        return "server/checklog/edit" ;
    }

    /**
     * 保存
     */
    @Log("保存")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("server:checklog:add")
    public R save(ChecklogDO checklog) {
        if (checklogService.save(checklog) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @Log("修改")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("server:checklog:edit")
    public R update(ChecklogDO checklog) {
            checklogService.update(checklog);
        return R.ok();
    }

    /**
     * 删除
     */
    @Log("删除")
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("server:checklog:remove")
    public R remove( Long autoid) {
        if (checklogService.remove(autoid) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @Log("批量删除")
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("server:checklog:batchRemove")
    public R remove(@RequestParam("ids[]") Long[]autoids) {
            checklogService.batchRemove(autoids);
        return R.ok();
    }

    /**
     * tag
     */
    @GetMapping( "/almDesc")
    @ResponseBody
    public List<ChecklogDO> listDesc(){
        return checklogService.listDesc();
    }
    /**
     * tag
     */
    @GetMapping( "/almVal")
    @ResponseBody
    public List<ChecklogDO> listChkVal(){
        return checklogService.listChkVal();
    }
    /**
     * tag
     */
    @GetMapping( "/almLev")
    @ResponseBody
    public List<ChecklogDO> listAlmLev(){
        return checklogService.listAlmLev();
    }

}
